package com.woniuxy.adminservice.rabbit;

import com.woniuxy.admindao.mapper.AdminLoginLogMapper;
import com.woniuxy.admindao.mapper.AdminMapper;
import com.woniuxy.admindao.model.Admin;
import com.woniuxy.admindao.model.AdminLoginLog;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Component
public class AdminLoginLogListener {
    @Resource
    private AdminMapper adminMapper;
    @Resource
    private AdminLoginLogMapper adminLoginLogMapper;
    @RabbitListener(queuesToDeclare = {@Queue(value = "admin-login-log")})
    public void AdminLoginLogHandler(Map<String, Object> map){
        Admin admin = adminMapper.selectById(((Integer) map.get("adminId")));
        AdminLoginLog adminLoginLog = new AdminLoginLog();
        adminLoginLog.setAdminId(admin.getAdminId());
        adminLoginLog.setAdminAccount(admin.getAdminName());
        adminLoginLog.setLoginTime(((String) map.get("loginTime")));
        adminLoginLog.setLoginAddr(((String) map.get("loginAddr")));
        adminLoginLogMapper.insert(adminLoginLog);
    }
}
